---
category: Validator
created: '2021-04-10'
title: Check if a value is base64 encoded
updated: '2021-10-13'
---

**JavaScript version**

```js isBase64.js
const isBase64 = (value) =>
    /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
```

**TypeScript version**

```ts isBase64.ts
const isBase64 = (value: string): boolean =>
    /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
```
